package com.taiyuan.tongcheng.ui;

import org.kymjs.kjframe.ui.BindView;

import com.tytc56.user.R;

import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class TcWebviewActivity extends BaseActivity
{
	@BindView(id=R.id.webview_content)
   	private WebView   mWebView;
	
    //tag 标记;
	public static final int TAG_MOVING_INFORM =1;
	public static final int TAG_HUZHU_INFROM   =2;
	public static final int TAG_CARGO_INFORM  =3;
	public static final String TAG_COMFROM="COME_FROM";
	public static final String TAG_TOP_TITLE="TOP_TITLE";
	private int    comFrom=0;
	private String topTitle="";
	//URL
	private  String HUOZHU_URL="file:///android_asset/huozhu.html ";
	private  String BANJIA_URL="file:///android_asset/bjsm.html ";
	private  String ZHENGCHE_URL="file:///android_asset/zcsm.html ";
    
    @Override
    public void setRootView() {
    	super.setRootView();
    	setContentView(R.layout.activity_webview);
    }
    
    @Override
    public void initWidget() {
    	super.initWidget();
    	initView();
    	topTitle=getIntent().getStringExtra(TAG_TOP_TITLE);
    	topTv.setText(topTitle);
    	rightTv.setVisibility(View.GONE);
    	comFrom=getIntent().getIntExtra(TAG_COMFROM, 0);
    	switch (comFrom) {
		case TAG_MOVING_INFORM:
			mWebView.loadUrl(BANJIA_URL);
			break;
		case TAG_CARGO_INFORM:
			mWebView.loadUrl(ZHENGCHE_URL);
			break;
		case TAG_HUZHU_INFROM:
			mWebView.loadUrl(HUOZHU_URL);
			break;

		default:
			break;
		}
		
    }
	
	public boolean onKeyDown(int keyCode, KeyEvent event) 
	{       
        if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) 
        {       
        	mWebView.goBack();       
            return true;       
        }       
        return super.onKeyDown(keyCode, event);       
    }
	
	@Override
	protected void onStop() 
	{
        super.onStop();
	}
	@Override
	protected void onDestroy() 
	{
		if(mWebView!=null){

			final ViewGroup viewGroup = (ViewGroup) mWebView.getParent();
			if (viewGroup != null) {
				viewGroup.removeView(mWebView);
			}
			mWebView.destroy();
		
		}
        super.onDestroy();
	}
}
